package com.bw.module_home.ui.marketers

import android.util.Log
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_common.arouter.Router
import com.bw.lib_common.base.BaseActivity
import com.bw.module_home.R
import com.bw.module_home.databinding.ActivityMarketersDetailBinding
import com.bw.module_home.marketer.adapter.BusinessDetailPhotoAdapter
import com.bw.module_home.marketer.viewmodel.MarketersViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = Router.Ui.MarketersDetailActivity)
class MarketersDetailActivity : BaseActivity<MarketersViewModel, ActivityMarketersDetailBinding>() {
    private val viewModel: MarketersViewModel by viewModels()
    lateinit var businessDetailPhotoAdapter: BusinessDetailPhotoAdapter

    @Autowired
    @JvmField
    var id: Int = 0

    override val mLayoutResId: Int
        get() = R.layout.activity_marketers_detail

    override fun initView() {
        super.initView()
        ARouter.getInstance().inject(this)
        Log.d("detail_id", "${id}")
        mBinding.back.setOnClickListener {
            finish()
        }
        businessDetailPhotoAdapter = BusinessDetailPhotoAdapter()
        mBinding.businessRv.adapter = businessDetailPhotoAdapter
        mBinding.businessRv.layoutManager = LinearLayoutManager(this)
        viewModel.getBusinessProfileDetail(id)
    }

    override fun initListener() {
        super.initListener()
        viewModel.getBusinessProfileDetailSuccess.observe(this) {
            mBinding.entity = it
            val photos = if (it.photos.isNullOrEmpty()) {

                listOf("https://example.com/default.jpg","https://example.com/default.jpg")
            } else {
                it.photos
            }
            businessDetailPhotoAdapter.data.clear()
            businessDetailPhotoAdapter.data.addAll(photos)
//            businessDetailPhotoAdapter.data.addAll(it.photos)
            businessDetailPhotoAdapter.notifyDataSetChanged()
        }
    }
}